package com.example.chapter6;


import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class ServletConfigTest extends HttpServlet {
    private ServletConfig config;

    public ServletConfigTest() {
        super();
    }

    @Override
    public void destroy() {
    }
    @Override
    public void init(ServletConfig config) throws ServletException{
        super.init(config);
        this.config=config;
    }
    protected  void doPost(HttpServletRequest request, HttpServletResponse response) throws
           ServletException, IOException{
        String charset = this.config.getInitParameter("charset");
        response.setCharacterEncoding(charset);
        response.setContentType("text/html");
        PrintWriter out = response.getWriter();
        out.println("<HTML>");
        out.println("<HEAD><TITLE>ServletConfig</TITLE></HEAD>");
        out.println("<BODY>");
        out.println("获取IntParamServlet的初试化参数\"encoding\"的字符串值:"+charset);
        out.println("</BODY>");
        out.println("</HTML>");
        out.flush();
        out.close();
    }
    protected  void doGet(HttpServletRequest request, HttpServletResponse response) throws
            ServletException, IOException{
        doPost(request,response);
    }
    }
